package sfeir.gwt.ergosum.client;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FileUpload;
import com.google.gwt.user.client.ui.FormPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.InlineLabel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ImportDialog extends DialogBox {

    private class ImportFormPanel extends FormPanel {
        public ImportFormPanel() {
            setAction("/gwtergosum/import");
            setEncoding(ENCODING_MULTIPART);
            setMethod(METHOD_POST);
            Grid panel = new Grid(5, 2);
            setWidget(panel);
            panel.setWidget(0, 1, new Label("Caution : The imported profile will erase your current profile"));
            FileUpload upload = new FileUpload();
            upload.setName("uploadVCard");
            panel.setWidget(1, 0, new Label("VCard"));
            panel.setWidget(1, 1, upload);
            panel.setWidget(2, 0, new Label(".tel"));
            TextBox telTB = new TextBox();
            telTB.setName("telDomain");
            panel.setWidget(2, 1, telTB);
            panel.setWidget(3, 0, new Label("Website"));
            TextBox webTB = new TextBox();
            webTB.setName("webSite");
            panel.setWidget(3, 1, webTB);
            panel.setWidget(4, 0, new Button("Cancel", new ClickHandler() {
                public void onClick(ClickEvent event) {
                    event.preventDefault();
                    ImportDialog.this.hide();
                }
            }));
            panel.setWidget(4, 1, new Button("Submit", new ClickHandler() {
                public void onClick(ClickEvent event) {
                    submit();
                }
            }));
            addSubmitHandler(new FormPanel.SubmitHandler() {
                public void onSubmit(SubmitEvent event) {
                    // if (tb.getText().length() == 0) {
                    // Window.alert("The text box must not be empty");
                    // event.cancel();
                    // }
                }
            });
            addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
                public void onSubmitComplete(SubmitCompleteEvent event) {
                    // Window.alert(event.getResults());
                    // ImportDialog.this.hide();
                    Window.Location.assign("http://" + Window.Location.getHost() + "/ViewProfile.jsp");
                }
            });
        }
    }

    public ImportDialog() {
        setText("Import your profile");
        setWidget(new ImportFormPanel());
    }
}
